package com.atguigu.spring6.autowired.controller;


import com.atguigu.spring6.autowired.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class UserController {

    // 第一种方式 属性注入
//    @Autowired
//    private UserService userService;

    // 第二种方式 SET注入
//    private UserService userService;
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }

    // 第三种方式 构造注入
//    private UserService userService;
//    @Autowired
//    public UserController(UserService userService) {
//        this.userService = userService;
//    }

    // 第四种方式 形参注入
//    private UserService userService;
//    public UserController(@Autowired UserService userService) {
//        this.userService = userService;
//    }
//
    //第五种方式 只有一个有参数的构造，无注解
    private UserService userService;
    public UserController(UserService userService) {
        this.userService = userService;
    }

    public void addUser() {
        this.userService.addUserService();
        System.out.println("UserController addUser()");
    }
}
